package com.example.CarManagement.sys.controller;

import com.example.CarManagement.common.Result;
import com.example.CarManagement.sys.entity.Drivers;
import com.example.CarManagement.sys.service.impl.DriversServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 司机信息表，存储所有司机的专业信息和当前状态 前端控制器
 * </p>
 *
 * @author 徐佳彪
 * @since 2025-07-17
 */
@RestController
@RequestMapping("/sys/drivers")
public class DriversController {

    @Autowired
    private DriversServiceImpl driversService;


    // 分页查询司机信息
    @PreAuthorize("@se.hasPermi('DRIVERS_SELECT')")
    @GetMapping("/list")
    public Result<?> list(@RequestParam Integer pageNo, @RequestParam Integer pageSize, @RequestParam(required = false) String driverId) {
        return driversService.getDrivers(pageNo, pageSize, driverId);
    }

    // 添加司机信息
    @PreAuthorize("@se.hasPermi('DRIVERS_INSERT')")
    @PostMapping("/add")
    public Result<?> add(@RequestBody Drivers drivers) {
        return driversService.addDrivers(drivers);
    }

    // 修改司机信息
    @PreAuthorize("@se.hasPermi('DRIVERS_UPDATE')")
    @PutMapping("/update")
    public Result<?> update(@RequestBody Drivers drivers) {
        return driversService.updateDrivers(drivers);
    }

    // 更改司机状态

    // 更具ID查询司机信息
    @PreAuthorize("@se.hasPermi('DRIVERS_SELECT')")
    @GetMapping("/getById/{id}")
    public Result<?> getById(@PathVariable String id) {
        return driversService.getDriversById(id);
    }

    // 删除司机信息
    @PreAuthorize("@se.hasPermi('DRIVERS_DELETE')")
    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable String id) {
        return driversService.deleteDrivers(id);
    }


    // 分配汽车
    @PreAuthorize("@se.hasPermi('DRIVERS_ASSIGN')")
    @PutMapping("/assignCar/{driverId}/{carId}")
    public Result<?> assignCar(@PathVariable String driverId, @PathVariable String carId) {
        return driversService.assignCar(driverId, carId);
    }

}
